package com.xc.hotelmgr.webapi.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xc.hotelmgr.webapi.modules.sys.entity.ApiUserEntity;
import com.xc.hotelmgr.webapi.modules.sys.service.ApiUserService;
import com.xc.hotelmgr.webapi.common.utils.PageUtils;
import com.xc.hotelmgr.webapi.common.utils.R;



/**
 * 
 *
 * @author kemmy
 * @email kemmy@gmail.com
 * @date 2020-10-30 11:51:31
 */
@RestController
@RequestMapping("sys/apiuser")
public class ApiUserController {
    @Autowired
    private ApiUserService apiUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:apiuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = apiUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("sys:apiuser:info")
    public R info(@PathVariable("userId") Integer userId){
		ApiUserEntity apiUser = apiUserService.getById(userId);

        return R.ok().put("apiUser", apiUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:apiuser:save")
    public R save(@RequestBody ApiUserEntity apiUser){
		apiUserService.save(apiUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:apiuser:update")
    public R update(@RequestBody ApiUserEntity apiUser){
		apiUserService.updateById(apiUser);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:apiuser:delete")
    public R delete(@RequestBody Integer[] userIds){
		apiUserService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
